import java.math.BigDecimal;
import java.util.Iterator;


import Border.Direction;
import Coordinates.Axis;
import Dungeon.*;
import Predicate.Predicate;
import Square.*;


public class MainProgram {


	public static void main(String[] args) {
		CompositeDungeon<Square> compositeDungeon = new CompositeDungeon<Square>(10,10,10);
		Shaft<Square> shaft = new Shaft<Square>(5, Axis.X_AXIS);
		Level<Square> level = new Level<Square>(5, 5);
		RegularSquareTeleporter shaftTeleporter = new RegularSquareTeleporter(10, new BigDecimal(10), Direction.FLOOR);
		RegularSquare shaftSquare = new RegularSquare(10, new BigDecimal(10), Direction.CEILING);
		RegularSquare levelSquare1 = new RegularSquare(10, new BigDecimal(20), Direction.CEILING);
		RegularSquare levelSquare2 = new RegularSquare(10, new BigDecimal(20), Direction.CEILING);
		RegularSquare levelSquare3 = new RegularSquare(10, new BigDecimal(20), Direction.CEILING);
		RegularSquare levelSquare4 = new RegularSquare(10, new BigDecimal(20), Direction.CEILING);
		RegularSquare levelSquare5 = new RegularSquare(10, new BigDecimal(20), Direction.CEILING);
		try {
		level.addSquare(levelSquare1, 2, 1, 0);
		level.addSquare(levelSquare2, 2, 0, 0);
		level.addSquare(levelSquare3, 3, 0, 0);
		level.addSquare(levelSquare4, 1, 1, 0);
		level.addSquare(levelSquare5, 1, 2, 0);
		shaft.addSquare(shaftTeleporter, 3, 0, 0);
		shaft.addSquare(shaftSquare, 2, 0, 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		compositeDungeon.addDungeon(  shaft, 0, 0, 1);
		compositeDungeon.addDungeon(  level, 0, 0, 0);
		shaftTeleporter.addDestination(levelSquare1);
		System.out.println("To how many squares can the shaftTeleporter teleport to?   " + shaftTeleporter.getAmountOfDestinations());
		System.out.println("___________________");
		System.out.println("");
		System.out.println("Checks how many squares are connected to eachother in the shaft, only done by open spaces");
		System.out.println("The amount of connected squares in the shaft:       "+shaftSquare.getAllLinkedSquares().size()) ;
		System.out.println("___________________");
		System.out.println("");
		System.out.println("Checks how many squares are connected to eachother in the level dungeon, only done by open spaces");
		System.out.println("The amount of connected squares in the level:       "+levelSquare1.getAllLinkedSquares().size()) ;
		System.out.println("");
		System.out.println("Checks which squares the shaftSquare can reach, this is done by teleportation or movement " +
				"in the spaces.");
		System.out.println("___________________");
		System.out.println("Checks if he can reach all the squares in the shaft.");
		System.out.println("");
		System.out.println("Can reach shaftSquare  		:" +shaftSquare.canReachSquare(shaftSquare));
		System.out.println("Can reach shaftTeleporter 	:" +shaftSquare.canReachSquare(shaftTeleporter));
		System.out.println("___________________");
		System.out.println("Checks if he can reach all the squares in the level.");
		System.out.println("");
		System.out.println("Can reach levelSquare1 		:" +shaftSquare.canReachSquare(levelSquare1));
		System.out.println("Can reach levelSquare2 		:" +shaftSquare.canReachSquare(levelSquare2));
		System.out.println("Can reach levelSquare3 		:" +shaftSquare.canReachSquare(levelSquare3));
		System.out.println("Can reach levelSquare4 		:" +shaftSquare.canReachSquare(levelSquare4));
		System.out.println("Can reach levelSquare5 		:" +shaftSquare.canReachSquare(levelSquare5));
		
		Rock rock1 = new Rock();
		Rock rock2 = new Rock();
		
		shaft.addSquare(rock1, 4, 0, 0);
		level.addSquare(rock2, 3, 1, 0);
		Iterator<Square> it = compositeDungeon.getIterator( new Predicate<Square>() {
			@Override
			public boolean apply(Square object) {
				return object.getClass() == Rock.class;
			}
		});
		
		
		System.out.println();
		System.out.println("== Iterator demo ==");
		while(it.hasNext())
		{
			Square next = it.next();
			if(next == rock1)
				System.out.println("This square equals the rock in the shaft");
			else if(next == rock2 )
				System.out.println("This square equals the rock in the level");
			else
				System.out.println("This square shouldn't be in this iterator");
		}
	}
}
